package app.server.project.main.service.db.entity.user;


import app.server.project.core.syndb.SynDBMgr;
import app.server.project.core.syndb.SynSpeed;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.time.LocalDateTime;

@Data
@Entity(name = "user_withdraw_detail")
@TableName("user_withdraw_detail")
@Comment(value = "用户提现明细")
@SynSpeed
public class UserWithDrawDetailEntity {

    @Id
    @Column(name = "id")
    @Comment("主键")
    @TableId("id")
    @JsonSerialize(using = ToStringSerializer.class)
    private long id;


    @Column(name = "user_id")
    @Comment("用户id")
    @TableField("user_id")
    @JsonSerialize(using = ToStringSerializer.class)
    private long userId;

    @Column(name = "rate")
    @Comment("比率")
    @TableField("rate")
    @JsonSerialize(using = ToStringSerializer.class)
    private long rate;

    @Column(name = "name")
    @Comment("代币名称")
    @TableField("name")
    private String name;

    @Column(name = "val")
    @Comment("代币数量")
    @TableField("val")
    @JsonSerialize(using = ToStringSerializer.class)
    private long val;

    @Column(name = "wallet_location")
    @Comment("钱包地址")
    @TableField("wallet_location")
    private String walletLocation;

    @TableField("status")
    @Comment("0 未完成 1 提现成功")
    @Column(name = "status")
    private int status;

    @Column(name = "race_id")
    @Comment("代币id")
    @TableField("race_id")
    private int raceId;

    @TableField("create_time")
    @Comment("创建时间")
    @Column(name = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Column(name = "money")
    @Comment("金额")
    @TableField("money")
    private String money;

    @Column(name = "nick")
    @Comment("昵称")
    @TableField("nick")
    private String nick;

    @Column(name = "pass_time")
    @Comment("审核通过时间")
    @TableField("pass_time")
    private LocalDateTime passTime;


    @TableField("block_type")
    @Column(name = "block_type")
    @Comment("区块类型")
    private String blockType;

    @JsonIgnore
    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public static UserWithDrawDetailEntity of(long id) {
        var ret = new UserWithDrawDetailEntity();
        ret.setSynDb(true);
        ret.setId(id);
        ret.setCreateTime(LocalDateTime.now());
        return ret;
    }

    public void setPassTime(LocalDateTime passTime) {
        this.passTime = passTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getPassTime, this);
    }

    public void setMoney(String money) {
        this.money = money;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getMoney, this);
    }

    public void setNick(String nick) {
        this.nick = nick;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getNick, this);
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getCreateTime, this);
    }

    public void setRaceId(int raceId) {
        this.raceId = raceId;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getRaceId, this);
    }

    public void setUserId(long userId) {
        this.userId = userId;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getUserId, this);
    }

    public void setRate(long rate) {
        this.rate = rate;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getRate, this);
    }

    public void setName(String name) {
        this.name = name;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getName, this);
    }

    public void setVal(long val) {
        this.val = val;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getVal, this);
    }

    public void setWalletLocation(String walletLocation) {
        this.walletLocation = walletLocation;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getWalletLocation, this);
    }

    public void setStatus(int status) {
        this.status = status;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getStatus, this);
    }

    public void setBlockType(String blockType) {
        this.blockType = blockType;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(UserWithDrawDetailEntity::getBlockType, this);
    }
}
